from openpyxl import load_workbook
from openpyxl import Workbook


class execl_Util:

    @staticmethod
    def get_sheets(url):
        wb = load_workbook(url)
        sheets = []
        for name in wb.sheetnames:
            sheet = wb[name]
            sheets.append(sheet)
        return sheets

    @staticmethod
    def get_sheet(url, table_name):
        wb = load_workbook(url)
        sheet = wb.get_sheet_by_name(table_name)
        return sheet

    @staticmethod
    def get_sheet_data(sheet):
        test_sheet = []
        for value in list(sheet.values):
            test_sheet.append(value)
        return test_sheet

    @staticmethod
    def row_writer(sheet, row):
        sheet.append(row)

    @staticmethod
    def sheet_writer(sheet_names, datas, url):
        wb = Workbook()
        index = 0
        row_index = 0
        while index < len(sheet_names):
            sheet = wb.create_sheet(sheet_names[index].title)
            index = index + 1
            while row_index < len(datas):
                execl_Util.row_writer(sheet, datas[row_index])
                row_index = row_index + 1
        wb.save(url)
